package com.example.educate.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.educate.model.vod.Course;
import com.example.educate.result.Result;
import com.example.educate.service.CourseService;
import com.example.educate.vo.vod.CourseFormVo;
import com.example.educate.vo.vod.CoursePublishVo;
import com.example.educate.vo.vod.CourseQueryVo;
import com.example.educate.vo.vod.CourseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author AT
 * @since 2022-09-18
 */
@RestController
@RequestMapping("/admin/vod/course")
@Api(tags="课程接口")
//@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;


    @ApiOperation("课程分页查询")
    @GetMapping("{page}/{limit}")
    public Result CourseList(@PathVariable Long page, @PathVariable Long limit,
                             @ApiParam(name = "courseVo", value = "查询对象", required = false)
                            CourseQueryVo courseQueryVo){
        Page<Course> page1 = new Page<>(page, limit);
        Map<String,Object> map= courseService.findPageCourse(page1,courseQueryVo);
        return Result.ok(map);
    }
    @ApiOperation("添加课程基本信息")
    @PostMapping("save")
    public Result save(@RequestBody CourseFormVo courseFormVo){
        Long courseId = courseService.saveCourseInFo(courseFormVo);
        return Result.ok(courseId);
    }
    //根据课程id获取信息值
    @ApiOperation("根据课程id获取课程信息")
    @GetMapping("getCourseInfo/{id}")
    public Result getCourseInfo(@PathVariable Long id){
       CourseFormVo courseFormVo=courseService.getCourseInfoById(id);
       return Result.ok(courseFormVo);
    }
    @ApiOperation("修改课程信息成功")
    @PostMapping("update")
    public Result update(@RequestBody CourseFormVo courseFormVo){
        courseService.updateCourseId(courseFormVo);
        return Result.ok(courseFormVo);
    }
    @ApiOperation("根据课程id查询课程信息")
    @GetMapping("getCoursePublishVo/{id}")
    public Result getCoursePublishVo(@PathVariable Long id){
        CoursePublishVo coursePublishVo= courseService.getCoursePublishVo(id);
        return Result.ok(coursePublishVo);
    }
    @ApiOperation("课程最终发布")
    @PutMapping("publishCourse/{id}")
    public Result publishCourse(@PathVariable Long id){
        courseService.publishCourse(id);
        return Result.ok(null);
    }
    @ApiOperation("根据课程id删除课程")
    @DeleteMapping("deleteCourse/{id}")
    public Result deleteCourse(@PathVariable Long id){
        courseService.removeById(id);
        return Result.ok(null);
    }

}
